package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Goods;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.bean.goods.GoodsCatAndBrand;
import com.cskaoyan.bean.goods.GoodsData;
import com.cskaoyan.service.AdminGoodsService;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ser.Serializers;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author xudengfeng
 * @date 2020/12/5 16:40
 */
@RestController
@RequestMapping("admin/goods")
public class AdminGoodsController {

    @Autowired
    AdminGoodsService adminGoodsService;

    @RequestMapping("list")
    public BaseRespVo goodsList(Integer page, Integer limit, String sort, String order, String goodsSn, String name) {
        ListData<Goods> goodsList = adminGoodsService.queryGoods(page, limit, sort, order, goodsSn, name);
        return BaseRespVo.ok(goodsList);
    }

    @PostMapping("delete")
    public BaseRespVo deleteGoods(@RequestBody Goods goods) {
        int i = adminGoodsService.deleteGoodsById(goods);
        return BaseRespVo.ok();
    }

    @GetMapping("detail")
    public BaseRespVo goodsDetail(Integer id) {
        GoodsData goodsData = adminGoodsService.queryGoodsData(id);
        return BaseRespVo.ok(goodsData);
    }

    @GetMapping("catAndBrand")
    public BaseRespVo catAndBrand() {
        GoodsCatAndBrand goodsCatAndBrand = adminGoodsService.queryCatAndBrand();
        return BaseRespVo.ok(goodsCatAndBrand);
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody GoodsData goodsData) {
        adminGoodsService.updateGoodsInfo(goodsData);
        return BaseRespVo.ok();
    }

    //上架商品
    @PostMapping("create")
    public BaseRespVo create(@RequestBody GoodsData goodsData) {
        adminGoodsService.createGoods(goodsData);
        return BaseRespVo.ok();
    }
}
